import { defineStore } from "pinia";
import { getStorage, removeStorage,setStorage } from "./storage";

interface UserInfo {
  userId: string,
  userName:string
}

export const useUserStore = defineStore("user", {
  state: () => {
    return {
      token: getStorage("token"),
      userInfo: {userId:'',userName:''} as UserInfo,
    };
  },
  actions: {
    logout() {
      // removeStorage("token");
      this.userInfo = {userId:'',userName:''}
    },
    login(userId: string, userName: string) {
      this.userInfo.userId = userId
      this.userInfo.userName=userName
      
    },
    getUserInfo():UserInfo {
      return this.userInfo
    }
  },
  getters: {
    user: (state) => {
      return state.userInfo
    }
  },
  persist:true
});